package com.vrv.netmgr.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;
import android.util.Log;

import com.vrv.common.GlobalConstants;
import com.vrv.common.util.CheckNetStatus;
import com.vrv.netmgr.EdpApplication;
/**
 * 监听网络状态变化
 * 在网络可通的情况下，尝试和服务器连接
 * 将和服务建立连接成功或者失败记录到本地
 * 在访问数据是，根据本地记录情况选择1是否更新后台数据，2是否访问本地数据库结果
 * 
 * 必须保证wifi可通，目前软件只能在wifi环境下运行
 * @author zxb
 *
 */
public class NetStatusBroadcastReceiver extends BroadcastReceiver {
    private static final String TAG = NetStatusBroadcastReceiver.class.getSimpleName();
    private static final boolean DEBUG = true && GlobalConstants.DEBUG;
    
	@Override
	public void onReceive(Context context, Intent intent) {
		// TODO Auto-generated method stub
		if (DEBUG) Log.v(TAG, "onReceive()");
		
		new Thread() {
			public void run(){
				if (DEBUG) Log.v(TAG, "onReceive()...Thread()...run()");
				
            
                boolean bWifi = false;
                boolean bServer = false;
                
            	//探测wifi
                bWifi = CheckNetStatus.detectWifi();
                
                if (bWifi) {
                	//探测服务器
                	bServer = CheckNetStatus.detectServer();
        		}
            	
            	boolean status = bWifi & bServer;
            	
            	EdpApplication.setNetStatus(status);
			}
		}.start();
	}
}
